<template>
  <div class='search'>
    <f-drawer ref='salemanDrawer' title='业务员审批' width='70%' okText='审批' @submit='handleSubmit' @visibleChange='visibleChange'>
      <saleman-form ref='form1' v-if='drawerVisible'></saleman-form>
      <task-todo-form-modal ref='taskTodoFormModal' handler-name='saleManDataHandler' @callback='handleSuccess'></task-todo-form-modal>
    </f-drawer>
  </div>
</template>
<script>
import salemanForm from "./saleman_form.vue"
import TaskTodoFormModal from "@/views/module/haiying/tasktodo/tasktodo_form_modal"


export default {
  name: "salemanDrawer",
  props: {},
  data() {
    return {
      refs: this.$refs,
      drawerVisible: false,
      isEdit: false,
      title: "业务员详情",
      current: "form1",
      formData: {},
      forms: [
        "form1",
        "form2"
      ]
    }
  },
  methods: {
    showDrawer(data) {
      this.isEdit = false
      if (data && data.saleManId) {
        this.isEdit = true
        this.formData = data
      } else {
        this.formData = { deptId: data.deptId }
      }
      this.refs["salemanDrawer"].show()
      this.tabClick("form1")
    },
    handleSuccess() {
      this.$refs.salemanDrawer.close()
      this.$emit("success", true)
    },
    handleSubmit() {
      this.$refs.taskTodoFormModal.open(this.formData)
    },
    visibleChange(drawerVisible) {
      this.$emit("success")
      this.drawerVisible = drawerVisible
    },
    tabClick(name) {
      this.current = name
      this.$nextTick(() => {
        this.refs[this.current].setData(this.formData)
      })
    }
  },
  computed: {
    drawerTitle: function() {
      return this.title
    }
  },
  created() {
  },
  components: { TaskTodoFormModal, salemanForm }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
